$INCLUDE: 'C:\FG\FASTGRAF.FI'

      PROGRAM MAIN

      INTEGER NEW_MODE, OLD_MODE
      INTEGER STATUS
      INTEGER FG_ALLOCCMS, FG_ALLOCEMS, FG_ALLOCXMS
      INTEGER FG_BESTMODE, FG_FREEPAGE, FG_GETMODE
      INTEGER FG_INITEMS, FG_INITXMS

      CALL FG_INITPM
      NEW_MODE = FG_BESTMODE(320,200,1)
      IF (NEW_MODE .LT. 0 .OR. NEW_MODE .EQ. 12) THEN
         STOP 'This program requires a 320 x 200 color graphics mode.'
      END IF
      OLD_MODE = FG_GETMODE()
      CALL FG_SETMODE(NEW_MODE)

      STATUS = FG_INITXMS()
      IF (STATUS .EQ. 0) STATUS = FG_ALLOCXMS(8)
      IF (STATUS .LT. 0) THEN
         STATUS = FG_INITEMS()
         IF (STATUS .EQ. 0) STATUS = FG_ALLOCEMS(8)
      END IF
      IF (STATUS .LT. 0) STATUS = FG_ALLOCCMS(8)

      IF (STATUS .LT. 0) THEN
         CALL FG_SETMODE(OLD_MODE)
         CALL FG_RESET
         STOP 'Unable to create logical page.'
      END IF

      CALL FG_SETCOLOR(7)
      CALL FG_RECT(0,319,0,199)
      CALL FG_SETCOLOR(9)
      CALL FG_LOCATE(12,18)
      CALL FG_TEXT('test',4)
      CALL FG_WAITKEY

      CALL FG_COPYPAGE(0,8)
      CALL FG_ERASE
      CALL FG_WAITKEY

      CALL FG_COPYPAGE(8,0)
      CALL FG_WAITKEY

      STATUS = FG_FREEPAGE(8)
      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END
